package com.boulderai.mcp.client;

/**
 * MCP客户端工厂类
 * 用于创建不同类型的MCP客户端实例
 */
public class McpClientFactory {
    
    /**
     * 创建WebSocket类型的MCP客户端
     * @return WebSocket MCP客户端实例
     */
    public static McpClient createWebSocketClient() {
        return new WebSocketMcpClient();
    }
    
    /**
     * 根据URI协议自动选择合适的客户端类型
     * @param serverUri 服务器URI
     * @return 对应的MCP客户端实例
     */
    public static McpClient createClient(String serverUri) {
        if (serverUri == null || serverUri.isEmpty()) {
            throw new IllegalArgumentException("Server URI cannot be null or empty");
        }
        
        String protocol = extractProtocol(serverUri);
        
        switch (protocol.toLowerCase()) {
            case "ws":
            case "wss":
                return createWebSocketClient();
            default:
                throw new IllegalArgumentException("Unsupported protocol: " + protocol);
        }
    }
    
    private static String extractProtocol(String uri) {
        int colonIndex = uri.indexOf(":");
        if (colonIndex == -1) {
            throw new IllegalArgumentException("Invalid URI format: " + uri);
        }
        return uri.substring(0, colonIndex);
    }
}